#!/usr/bin/env bash

if [ -n "$NVIM" ]; then
    export VISUAL="nvr -cc split --remote-wait +'set bufhidden=wipe'"
else
    export VISUAL="nvim"
fi

# Make neovim the default editor.
export EDITOR="$VISUAL"
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
export MANPAGER='nvim +Man!'
export MANWIDTH=999

# Increase Bash history size. Allow 32³ entries; the default is 500.
export HISTSIZE='32768'
# export HISTFILESIZE="${HISTSIZE}";
# Omit duplicates and commands that begin with a space from history.
export HISTCONTROL='ignoreboth'

# Prefer US English and use UTF-8.
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

# Highlight section titles in manual pages.
# export LESS_TERMCAP_md="$yellow";

# Always enable colored `grep` output.
export GREP_OPTIONS='--color=auto'

# PATH exports
export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
export PATH="$HOME/.nimble/bin:$PATH"
export PATH="$HOME/.pixi/bin:$PATH"
export PATH="$HOME/local/nvim/bin:$PATH"
export PATH="$HOME/local/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"

export PATH="$HOME/gitrepos/flutter/bin:$PATH"
export PATH="$HOME/gitrepos/ccls/Release/:$PATH"
export PATH="$HOME/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"
export CONVENTIONAL_COMMITS_PRECOMMIT_NOEMOJI=true

export FZF_TMUX_HEIGHT='70%'

export FZF_DEFAULT_OPTS="
 $FZF_DEFAULT_OPTS
 --ansi
 --height='80%'
 --multi
 --preview-window 'right'
 --preview '([[ -f {} ]] && (bat {})) || ([[ -d {} ]] && (tree {} | less)) || echo {} 2> /dev/null'
 --layout=reverse
 --bind tab:down
 --bind shift-tab:up
 --bind 'ctrl-space:toggle+down'
 --bind 'ctrl-h:toggle-preview'
 --bind 'ctrl-e:preview-down'
 --bind 'ctrl-y:preview-up'
 --bind 'ctrl-d:preview-half-page-down'
 --bind 'ctrl-u:preview-half-page-up'
 --bind 'ctrl-f:page-down'
 --bind 'ctrl-b:page-up'
 --bind 'ctrl-a:toggle-all'
 --bind 'ctrl-l:clear-query'
 --bind change:first
 --cycle
"

# Custom previews
_fzf_comprun() {
    local command=$1
    shift

    case "$command" in
        export | unset) fzf "$@" --preview "eval 'echo \$'{}" ;;
        ssh) fzf "$@" --preview 'dig {}' ;;
        *) fzf "$@" ;;
    esac
}
zle -N fzf_comprun _fzf_comprun

export HOMEBREW_CASK_OPTS="--appdir=~/Applications --fontdir=~/Library/Fonts"

export XPRESSDIR="$HOME/Applications/fico-xpress/xpressmp"

export NEXTWORD_DATA_PATH=~/local/dictionary/nextword-data-large

export PYTHONPYCACHEPREFIX="${PYTHONPYCACHEPREFIX:-$HOME/.pycache}"

[ -f "$HOME/.ghcup/env" ] && source "$HOME/.ghcup/env" # ghcup-env

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export PATH="$HOME/.juliaup/bin:$PATH"
export PATH="$HOME/.julia/bin:$PATH"
# Trust any Julia code on this computer.
export JULIA_PROJECT=@.

export PATH="$HOME/Applications/quarto/bin":$PATH
export PATH=$HOME/.nimble/bin:$PATH
